package top.zhangjianyong.blog.portal.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zhangjianyong.blog.annotation.ApiLog;
import top.zhangjianyong.blog.params.category.CategoryTreeParam;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.CategoryService;

/**
 * Portal分类接口
 *
 * @author zhangjianyong
 * @since 2024/8/11 下午3:26
 */
@RequestMapping("/portal/category")
@RestController("portalCategoryController")
@ApiLog(description = "博客分类管理接口") // 类级别注解，所有方法都会记录日志
public class CategoryController {

  private final CategoryService categoryService;

  public CategoryController(CategoryService categoryService) {
    this.categoryService = categoryService;
  }

  /** 获取分类树形结构 */
  @PostMapping("/tree")
  @ApiLog(description = "获取分类树形结构", logResponse = false) // 方法级别注解，不记录响应数据
  public ApiResponse tree(@RequestBody @Validated CategoryTreeParam param) {
    return categoryService.tree(param);
  }

  /** 获取分类列表（平铺结构，用于筛选展示） */
  @PostMapping("/list")
  @ApiLog(description = "获取分类列表") // 重点关注执行时间
  public ApiResponse list(@RequestBody @Validated CategoryTreeParam param) {
    return categoryService.list(param);
  }
}
